import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Shapes 1.15

MainView {
    id: root
    width: 800
    height: 391

    property var menuArray: [qsTr("比较"), qsTr("操作"), qsTr("计数"), qsTr("图形"), qsTr("角度"), qsTr("计价") ]
    property var menuleftArray: [0, 0, 0, 1, 0, 0]
    property var menuorderArray: [5] //菜单顺序
    property int menumax: menuorderArray.length//菜单个数
    property int menuindex: 1

    property int selectedSubView: menuorderArray[menuindex-1]
    property int selectedLeftView: menuleftArray[menuorderArray[menuindex-1]]
    property int selectedRightView: menuorderArray[menuindex-1]

    Component.onCompleted: {
        //mainLoader.visible=false;
    }
    onVisibleChanged: {
        if(visible)
        {
            valuePanel.startTimer()
            RateCalculationPanel.startTimer()
        }
        else
        {
            valuePanel.stopTimer()
            RateCalculationPanel.stopTimer()
        }
    }
    LightBar {      //哦哦，一行Button风格的显示，HH  HL  OK  LO  LL.
        id: lightBar
        x: 0
        y: 0
        width: 532
        height: 36
    }
    Item {
        id: leftItem
        x: 0
        y: 40
        width: 532
        height: 349
        property int currentViewIndex: 0

        ValuePanel {
            id: valuePanel
            enabled: root.selectedLeftView === 0
            visible: opacity > 0.01
            anchors.fill: parent

            selectedView: root.selectedLeftView
            index: 0
        }

        GraphPanel {
            id: graphPanel
            enabled: root.selectedLeftView === 1
            visible: opacity > 0.01
            anchors.fill: parent

            selectedView: root.selectedLeftView
            index: 1
        }
    }
    /*ValuePanel
    {
        id:valuePanel
        x: 0
        y: 40
    }*/
    Button
    {
        id:btnSwitchMode
        x: 584
        y: 6
        width: 180
        height: 50
        background: Rectangle{
            border.width: btnSwitchMode.down?1: 0
            color: btnSwitchMode.down?"#FF614B": "#C070B0"
            border.color: "#F0D070"
                }

        text: menuArray[menuorderArray[menuindex-1]]
        font.pixelSize: 25
        palette.buttonText: "white"
        //Connections {   //C 为什么使用Connections{}？
        //    target: btnSwitchMode
        onClicked: {
            //selectedSubView切换顺序1(操作)-0(比较)-2(计数)-3(图形)-1(操作)
            //selectedLeftView 0 值界面  1 图形界面
            if(menuindex === menumax)
            {
                menuindex = 1
            }
           else{
                menuindex = menuindex + 1                   
            }
            root.selectedSubView = menuorderArray[menuindex-1]
            root.selectedLeftView = menuleftArray[menuorderArray[menuindex-1]]
            root.selectedRightView = menuorderArray[menuindex-1]
            btnSwitchMode.text = menuArray[menuorderArray[menuindex-1]]
        }
    }
    Item {
        /* 通过控制多个控件的显示，
        */
        id: subItem0
        height: 325
        width: 253
        //anchors.left: 542
        //anchors.right: parent.right
        //anchors.top: 61
        property int currentViewIndex: 4
        x: 542
        y: 61
        ComparePanel {
            id: comparePanel
            enabled: root.selectedRightView === 0
            visible: opacity > 0.01
            anchors.fill: parent

            selectedView: root.selectedRightView    //C 哦哦，向内层传递外层的参数值。
            index: 0
        }
        OperationPanel {
            id: operationPanel
            enabled: root.selectedRightView === 1
            visible: opacity > 0.01
            anchors.fill: parent

            selectedView: root.selectedRightView
            index: 1
        }
        CountPanel {
            id: countPanel
            enabled: root.selectedRightView === 2
            visible: opacity > 0.01
            anchors.fill: parent

            selectedView: root.selectedRightView
            index: 2
        }

        GraphRightPanel {
            id: graphRightPanel
            enabled: root.selectedRightView === 3
            visible: opacity > 0.01
            anchors.fill: parent

            selectedView: root.selectedRightView
            index: 3
        }
        Angle{
            id: anglePanel
            enabled: root.selectedRightView === 4
            visible: opacity > 0.01
            anchors.fill: parent

            selectedView: root.selectedRightView
            index: 4
        }
        RateCalculationPanel{
            id: rateCalculationPanel
            enabled: root.selectedRightView === 5
            visible: opacity > 0.01
            anchors.fill: parent

            selectedView: root.selectedRightView
            index: 5
        }
    }

    Dialog {
        anchors.centerIn: parent
        id: saveWeightOKDialog
        //title: "提示"
        standardButtons: Dialog.Ok
        title:qsTr("保存成功！")
        modal: true
        closePolicy: "CloseOnEscape"
        onAccepted: saveWeightOKDialog.close()
        z:100
        //onRejected: console.log("Cancel clicked")
    }

    MyBuzyIndicator{
        anchors.centerIn: parent
        id: angleLoader
        visible:false
        z:101
    }
}
